package code.D1213;

/**
 * author : yeswater
 * date : 2023/12/12
 */

public class T098 {
    TreeNode max;
    public boolean isValidBST(TreeNode root) {
        if (root == null) {
            return true;
        }
        // 中序
        boolean left = isValidBST(root.left);
        if (!left) return false;

        if (max != null && root.val <= max.val) return false;

        max = root;

        boolean right = isValidBST(root.right);
        return right;
    }

    
    private class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(int val) { this.val = val; }
        TreeNode(int val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    
}
